<?php

namespace app\webactive\controller;

use app\common\cachemodel\zl3\Zl3FortuneYearActiveAwardRecord;

class FortuneYearActive2022 extends Auth2
{
    public function index()
    {
        $height = input('h/d', 0);
        $headers = $this->request->header();
        $headers = [
            'app-type' => $headers['app-type'] ?? '',
            'version' => $headers['version'] ?? '',
            'did' => $headers['did'] ?? '',
            'access-token' => $headers['access-token'] ?? '',
            'sign' => $headers['sign'] ?? '',
        ];

        $activeConfig = config('fortune_year_active.2022');

        $awardData = $activeConfig['award_data'];
        $goodData = $activeConfig['good_data'];
        $awardList = [];
        foreach ($awardData as $awardItem)
        {
            $awardList[] = [
                'cname' => $awardItem['cname'],
                'img1' => $awardItem['img1'],
                'img2' => $awardItem['img2'],
            ];
        }
        $awardNum = 1; // 剩余抽奖次数
        if ($this->user)
        {   // 已登陆
            $fortuneYearActiveAwardRecordModel = new Zl3FortuneYearActiveAwardRecord();
            // 获取用户已抽奖次数
            $num = $fortuneYearActiveAwardRecordModel->getAwardNum($this->user['id'], 2022);
            $awardNum = $activeConfig['award_num'] - $num;
        }

        return $this->fetch('fortuneyearactive2022/index', [
            'award_data' => $awardList,
            'headers' => json_encode($headers, true),
            'app_type' => $headers['app-type'],
            'is_login' => $this->user ? 1 : 0,
            'award_num' => $awardNum,
            'height' => $height,
            'is_show_nav' => true,
            'good_data' => $goodData
        ]);
    }
}